package mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
//@RequestMapping("/hello")
public class RequestMappingController {

    @RequestMapping(
            value = {"/testRequestMapping", "/test"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    public String success() {
        return "success";
    }

    @GetMapping("/testGetMapping")//指定请求为GET方式
    public String testGetMapping() {
        return "success";
    }

    @PostMapping("/testPostMapping")//指定请求为POST方式
    public String testPostMapping() {
        return "success";
    }
    //查看form表单是否支持put和delete请求方式
    @RequestMapping(value = "/testPut", method = RequestMethod.PUT)
    public String testPut() {
        return "success";
    }
    //params和headers属性
    @RequestMapping(
            value = "/testParamsAndHeaders",
            params = {"username","password=123456"},
            headers = {"Host=localhost:8080"}//匹配不成功报404错误
    )
    public String testParamsAndHeaders() {
        return "success";
    }
    //SpringMVC支持ant风格的路径
    /*
        ? ：表示任意的单个字符
        * ：表示任意的0个或多个字符
        **：表示任意的一层或多层目录
    **/
    //@RequestMapping(value = "/a?a/testAnt")
    //@RequestMapping(value = "/a*a/testAnt")
    @RequestMapping(value = "/**/testAnt")//只能使用/**/方式
    public String testAnt() {
        return "success";
    }
    //SpringMVC支持路径中的占位符（重点）  ------rest方式
    @RequestMapping("/testPath/{id}/{username}")//只能使用/**/方式
    public String testPath(@PathVariable("id")Integer id, @PathVariable("username")String username) {
        System.out.println("id:" + id + ",username:" + username);
        return "success";
    }
}
